package com.ad.payload.util;

import java.security.MessageDigest;

public class CryptUtil {

    /**
     * 双MD5加密,
     * @param source
     * @return
     */
    public static String md5md5(String source) {
        return md5(md5(source));
    }

    /**
     * md5加密，转换成了大写，判断时，需ignore case！！！
     * @param source
     * @return
     */
    public static String md5(String source) {
        StringBuffer sb = new StringBuffer(32);
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            byte[] array = md.digest(source.getBytes("utf-8"));
            for (int i = 0; i < array.length; i++) {
                // 非通用算法
                sb.append(Integer.toHexString((array[i] & 0xFF) | 0x100).toUpperCase().substring(1, 3));
            }
        } catch (Exception e) {
            return null;
        }

        return sb.toString();
    }

}
